package pe.com.hermes.hermetic.web.controller.reportes;

import pe.com.hermes.hermetic.beans.AuditBean;
import pe.com.hermes.hermetic.negocio.service.HermeticFacade;
import pe.com.hermes.hermetic.web.controller.base.IController;
import pe.com.hermes.hermetic.web.controller.base.IWebOpciones;
import pe.com.hermes.hermetic.web.controller.general.MostrarReporteController;

import pe.com.hermes.hermetic.web.forms.HMF4013Form;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;

@Controller
@SessionAttributes(value={"codOpci","desOpci"})
@RequestMapping("/mostrarHWF4013.html")
public class ConsistenciaAbonosController implements IController{
    protected final static Logger logger = Logger.getLogger(ConsistenciaAbonosController.class);
    @Autowired
    private HermeticFacade servicioHermetic;
    @Autowired
    private MostrarReporteController reporteFactory;
    @RequestMapping(method=RequestMethod.GET)    
    protected String showForm(ModelMap model,HttpServletRequest request)throws Exception{
        logger.info(this.getClass().toString()+" "+"metodo: GET");
        HMF4013Form form = new HMF4013Form();
        String fecha = servicioHermetic.getFechaHoy();
        form.setFechadesde(fecha);
        form.setFechahasta(fecha);
        String codOpci = IWebOpciones.CONSIS_ABON;
        String desOpci = servicioHermetic.getDesOpci(codOpci, request);
        model.put("codOpci",codOpci);
        model.put("desOpci",desOpci);
        model.put(FORM_KEY,form);
        AuditBean auditBean = new AuditBean(CONSIS_ABON);
        servicioHermetic.inseAudit(auditBean);
        return FORM_CONS_ABONO;
    }
    @RequestMapping(params="accion=mostrarReporte")
    protected void mostrarReporte(HttpServletRequest request ,HttpServletResponse response)throws Exception{
        logger.info(this.getClass().toString()+" "+"mostrarReporte");
        String codClie=(String)request.getSession(false).getAttribute("cliente");
        reporteFactory.mostraReporte(request,response,codClie);
    }
}
